package code.generate;

import code.generate.util.GenerateUtil;
import freemarker.template.TemplateException;
import org.apache.maven.plugins.annotations.Mojo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/3/23 12:46
 */
@Mojo(name = "gen")
public class GenMojo extends AbstractMojo {

    public static final String FILE_NAME = "code.properties";

    @Override
    public void execute() {
        System.out.println("start generator code====================================================================");
        Properties properties = getProperties(FILE_NAME);
        if (null == properties) {
            throw new RuntimeException(FILE_NAME + " is not exist......");
        }

        try {
            String controller = properties.getProperty("controller");

            GenerateUtil.genModel();
            if(!"false".equals(controller)){
                GenerateUtil.genController();
            }
            GenerateUtil.genService();
            GenerateUtil.genServiceImpl();
            GenerateUtil.genDao();
        } catch (SQLException | IOException | TemplateException e) {
            e.printStackTrace();
        }


        System.out.println("end generator code====================================================================");
    }

}
